package com.ruoyi.web.controller.grape;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.grape.domain.GrapePhen;
import com.ruoyi.grape.service.IGrapePhenService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物候期信息Controller
 * 
 * @author ld
 * @date 2023-11-18
 */
@RestController
@RequestMapping("/grape/phen")
public class GrapePhenController extends BaseController
{
    @Autowired
    private IGrapePhenService grapePhenService;

    /**
     * 查询物候期信息列表
     */
    @PreAuthorize("@ss.hasPermi('grape:phen:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrapePhen grapePhen)
    {
        startPage();
        List<GrapePhen> list = grapePhenService.selectGrapePhenList(grapePhen);
        return getDataTable(list);
    }

    /**
     * 导出物候期信息列表
     */
    @PreAuthorize("@ss.hasPermi('grape:phen:export')")
    @Log(title = "物候期信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrapePhen grapePhen)
    {
        List<GrapePhen> list = grapePhenService.selectGrapePhenList(grapePhen);
        ExcelUtil<GrapePhen> util = new ExcelUtil<GrapePhen>(GrapePhen.class);
        util.exportExcel(response, list, "物候期信息数据");
    }

    /**
     * 获取物候期信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('grape:phen:query')")
    @GetMapping(value = "/{phenId}")
    public AjaxResult getInfo(@PathVariable("phenId") Long phenId)
    {
        return success(grapePhenService.selectGrapePhenByPhenId(phenId));
    }

    /**
     * 新增物候期信息
     */
    @PreAuthorize("@ss.hasPermi('grape:phen:add')")
    @Log(title = "物候期信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrapePhen grapePhen)
    {
        return toAjax(grapePhenService.insertGrapePhen(grapePhen));
    }

    /**
     * 修改物候期信息
     */
    @PreAuthorize("@ss.hasPermi('grape:phen:edit')")
    @Log(title = "物候期信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrapePhen grapePhen)
    {
        return toAjax(grapePhenService.updateGrapePhen(grapePhen));
    }

    /**
     * 删除物候期信息
     */
    @PreAuthorize("@ss.hasPermi('grape:phen:remove')")
    @Log(title = "物候期信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{phenIds}")
    public AjaxResult remove(@PathVariable Long[] phenIds)
    {
        return toAjax(grapePhenService.deleteGrapePhenByPhenIds(phenIds));
    }
}
